#ifndef MESSAGEMODEL_H
#define MESSAGEMODEL_H

#include <QAbstractListModel>
#include <QDebug>
#include <QString>
#include <QHash>

class MessageModel : public QAbstractListModel
{
    Q_OBJECT

public:
    struct Contact {
        QString message;
        QString sendername;
        QString senderimg;
        int senderid;
        QString time;
        int msgtype;
    };
    enum ContactRole {
        MessageRole = Qt::DisplayRole,
        SendernameRole = Qt::UserRole,
        SenderimgRole,
        SenderidRole,
        TimeRole,
        MsgTypeRole
    };
    Q_ENUM(ContactRole)

    explicit MessageModel(QObject *parent = nullptr);

    // Basic functionality:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    QHash<int, QByteArray> roleNames() const;

    Q_INVOKABLE QVariantMap get(int row) const;

    Q_INVOKABLE void append(const Contact contact);

private:
    QList<Contact> m_contacts;
};

#endif // MESSAGEMODEL_H
